import axios from "axios"
import { MessageBox } from 'element-ui';
import storage from "./storage";

let http =axios.create({
    baseURL:"/api",
    timeout:4000,
    withCredentials:true

})

//全局的请求拦截，对接口的请求批量进行统一处理
http.interceptors.request.use(config=>{

    let token = storage.get("token")
    // console.log(token)
    config.headers['authorization'] =token

    return config
})

//全局响应拦截，统一对错误处理
http.interceptors.response.use(config=>{
    console.log("config",config)
    let {state,msg}=config.data
    if(!state){
        // console.log("错误")
        MessageBox({
            message:msg,
            title:"提示",
            type:"error"
        })

    }
    return config
})

export default http;
